package com.seckill.result;

import com.seckill.enums.ResultEnum;

public class Result<T> {
    private int code;
    private String msg;
    private T t;

    public Result(ResultEnum resultEnum){
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
    }

    public Result(ResultEnum resultEnum, T t){
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
        this.t = t;
    }

    public static <T>Result<T> success(T t){
        return new Result<T>(ResultEnum.SUCCESS, t);
    }

    public static <T>Result<T> error(ResultEnum resultEnum){
        return new Result<T>(resultEnum);
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", t=" + t +
                '}';
    }

    public static void main(String[] args) {
        System.out.println(Result.error(ResultEnum.SERVER_ERROR));
        System.out.println(Result.success("yanshang"));
    }
}
